#pragma once

#include "SimpleSocket.h"
#include "SimpleEvent.h"

namespace RoomFW {

//
// Class:	SocketEvent
//
// Description:	Class to associate a socket with an event for windows to set
//				when specified socket events happen.
//
// Author:	Andrew Sage
//
class SocketEvent
{
public:

	//
	// Method:	SocketEvent
	//
	// Description:	Constructor
	//
	// Parameters:	None
	//
	SocketEvent(SimpleSocket::SocketPtr socket = SimpleSocket::SocketPtr(new SimpleSocket()));

	//
	// Method:	~SocketEvent
	//
	// Description:	Destructor
	//
	~SocketEvent();

	//
	// Method:	initialize
	//
	// Description:	Create the event and associate it specified socket events.
	//
	// Parameters:
	//
	//	events - Socket events.  See ::WSAEventSelect().
	//
	// Return:	Success.
	//
	bool initialize(long events);

	//
	// Method:	getSocketPtr
	//
	// Description:	Get contained socket pointer.
	//
	// Parameters:	None.
	//
	// Return:	Contained socket pointer.
	//
	SimpleSocket::SocketPtr getSocketPtr(void) const;

	//
	// Method:	getEventHandle
	//
	// Description:	Get contained event handle.
	//
	// Parameters:	None.
	//
	// Return:	Contained event handle.
	//
	HANDLE getEventHandle(void) const;

	//
	// Method:	enumNetworkEvents
	//
	// Description:	Call ::WSAEnumNetworkEvents() with contained socket and
	//	event handle and supplied WSANETWORKEVENTS.
	//
	// Parameters:
	//
	//	networkEvents - Network events for contained socket.
	//
	// Return:	Success.
	//
	bool enumNetworkEvents(WSANETWORKEVENTS& networkEvents) const;

private:

	//
	// Socket pointer.
	//
	SimpleSocket::SocketPtr socket_;

	//
	// Event handle.
	//
	SimpleEvent event_;

	//
	// Initialized flag.
	//
	bool initialized_;

	//
	// Non-copy-able!
	//
	SocketEvent(const SocketEvent&);
	SocketEvent& operator=(const SocketEvent&);

};
typedef ::boost::shared_ptr<SocketEvent> SocketEventSP;

}
